package vip.ifmm.lehouse.mq.service;

import com.alibaba.dubbo.config.spring.context.annotation.EnableDubbo;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.PropertySource;
import vip.ifmm.lehouse.common.util.RocketMqUtil;
import vip.ifmm.lehouse.mq.service.api.impl.RocketMqServiceImpl;

import javax.annotation.PreDestroy;
import java.io.UnsupportedEncodingException;
import java.util.List;

@SpringBootApplication
@EnableDubbo
@PropertySource(value = "classpath:properties/constants.properties", encoding = "utf-8")
@Slf4j
public class LehouseMqServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(LehouseMqServiceApplication.class, args);
    }


    // 关闭所有生产者
    @PreDestroy
    public void closeProducers() {
        for(DefaultMQProducer producer  : RocketMqServiceImpl.producerList ) {
            producer.shutdown();
        }
        log.info("生产者销毁完毕...");
    }
}
